<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script>
			let str = "           1 23  \t     ";
			console.log(str);
			let str1 = str.trim();
			console.log(str1);
			
			function doTrim(str) {
				// 获取字符串长度
				let length = str.length;
				let begin = 0;
				let end = str.length;
				
				for (let i = 0;i < str.length;i ++) {
					let c = str.charAt(i);
					if (c <= ' ') {
						begin = i + 1;
					} else {
						break;
					}
				}
				
				for (let i = str.length - 1;i >= 0;i --) {
					let c = str.charAt(i);
					if (c <= ' ') {
						length --;
					} else {
						break;
					}
				}
				
				return begin > 0 || length < str.length ? str.substr(begin,end) : str;
				
			}
			
			str1 = doTrim(str);
			console.log(str1);
		</script>
	</body>
</html>
